home *** CD-ROM | disk | FTP | other *** search
- // Dynamic link library implementation of binary file translator with offset and duration
-
- #include "NSDLL.h"
- #include <stdio.h>
-
- /**********************************/
- /* Read next sample from file */
- __declspec(dllexport) BOOL performFile(
- DLLData *instance, // Pointer to instance data (may be NULL)
- FILE *file, // Pointer to the opened file
- NSFloat *sample // Location to place next sample
- )
- {
- int duration = getIntParameter(instance, 2, 1);
- int *durationCount = (int*)getUserData(instance);
- unsigned int typedSample;
- if ((!duration || ((*durationCount)++ < duration)) && fread(&typedSample, sizeof(unsigned int), 1, (FILE*)file)) {
- *sample = (NSFloat)typedSample;
- return TRUE;
- }
- *durationCount = 0;
- fclose((FILE*)file);
- return FALSE;
- }
-
- /********************************************/
- /* Open and the file and return its pointer */
- __declspec(dllexport) FILE *openFile(DLLData *instance, const char *filePath)
- {
- unsigned int *buffer;
- FILE *file = fopen(filePath, "rb");
- int offset = getIntParameter(instance, 1, 1);
-
- if (offset) {
- buffer = malloc(offset*sizeof(unsigned int));
- fread(buffer, sizeof(unsigned int), offset, file);
- free(buffer);
- }
- return file;
- }
-
- /******************************************/
- /* Management of instance data (OPTIONAL) */
-
- __declspec(dllexport) DLLData *allocFile(
- DLLData *oldInstance // Pointer to the last instance if reallocating
- )
- {
- DLLData *instance = allocDLLInstance(oldInstance);
- setParameterName(instance, 1, 1, "Offset", FALSE);
- setIntParameter(instance, 1, 1, 0, FALSE);
- setParameterName(instance, 2, 1, "Duration", FALSE);
- setIntParameter(instance, 2, 1, 0, FALSE);
- setUserData(instance, calloc(1,sizeof(int)));
- return instance;
- }
-
- __declspec(dllexport) void freeFile(DLLData *instance)
- {
- if (getUserData(instance))
- free((int*)getUserData(instance));
- freeDLLInstance(instance);
- }
-
-